<div dir="ltr">Hey avinash,<div><br></div><div>By default, Jiffy returns "EJSON", not a map. It looks liked you need to use an Option for Jiffy to return a map.</div><div><br></div><div>```erlang</div>Tx=jiffy:decode(<<"{\"foo\": \"bar\",\"key\": \"val\"}">>, [return_maps]).<div>```</div><div><br></div><div><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif"><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:inherit;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">jiffy:decode/1,2</code></h2><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:16px;line-height:25.6000003814697px"><li style="box-sizing: border-box;"><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">jiffy:decode(IoData)</code></li><li style="box-sizing: border-box;"><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">jiffy:decode(IoData, Options)</code></li></ul><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:16px;line-height:25.6000003814697px">The options for decode are:</p><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:16px;line-height:25.6000003814697px"><li style="box-sizing: border-box;"><span style="background-color:rgb(255,255,0)"><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px">return_maps</code> - Tell Jiffy to return objects using the maps data type on VMs that support it. This raises an error on VMs that don't support maps.</span></li><li style="box-sizing: border-box;"><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">{null_term, Term}</code> - Returns the specified <code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">Term</code> instead of <code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">null</code> when decoding JSON. This is for people that wish to use <code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">undefined</code> instead of <code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">null</code>.</li><li style="box-sizing: border-box;"><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">use_nil</code> - Returns the atom <code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">nil</code> instead of <code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">null</code> when decoding JSON. This is a short hand for <code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">{null_term, nil}</code>.</li><li style="box-sizing: border-box;"><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">return_trailer</code> - If any non-whitespace is found after the first JSON term is decoded the return value of decode/2 becomes <code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">{has_trailer, FirstTerm, RestData::iodata()}</code>. This is useful to decode multiple terms in a single binary.</li><li style="box-sizing: border-box;"><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">{bytes_per_red, N}</code> where N >= 0 - This controls the number of bytes that Jiffy will process as an equivalent to a reduction. Each 20 reductions we consume 1% of our allocated time slice for the current process. When the Erlang VM indicates we need to return from the NIF.</li><li style="box-sizing: border-box;"><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">{bytes_per_iter, N}</code> where N >= 0 - Backwards compatible option that is converted into the <code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6000003814697px;padding:0.2em 0px;margin:0px;border-radius:3px;background-color:rgba(0,0,0,0.0392157)">bytes_per_red</code> value.</li></ul></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jul 25, 2015 at 7:22 AM, avinash D'silva <span dir="ltr"><<a href="mailto:evnix.com@gmail.com" target="_blank">evnix.com@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I have the following code.
<div><div> Tx=jiffy:decode(<<"{\"foo\": \"bar\",\"key\": \"val\"}">>).</div><div><br></div><div>where Tx is:</div><div>{[{<<"foo">>,<<"bar">>},{<<"key">>,<<"val">>}]}</div></div><div><br></div><div>I tried the following:</div><div><br></div><div><div>maps:get("foo",Tx).   </div><div>** exception error: {badmap,{[{<<"foo">>,<<"bar">>},{<<"key">>,<<"val">>}]}}</div><div>     in function  maps:get/2</div><div>        called as maps:get("foo",</div><div>                           {[{<<"foo">>,<<"bar">>},{<<"key">>,<<"val">>}]})</div></div><div><br></div><div>Any Idea on what I am doing wrong? any possible solutions?</div><div>I Couldn't find any documentation to access this type of map.</div><div><br></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>