OpenersPrimaryExamplesSection(Spacer1)Examples  (5)

OpenersExampleSection0(Spacer1)Basic Examples  (5)

Import a JSON list:

ImportString["[ \"List\", 1, 2, 3 ]", "ExpressionJSON"]

Import a (RefLink[String, paclet:ref/String]):

ImportString["\"'abc'\"", "ExpressionJSON"]

Import a (RefLink[Quantity, paclet:ref/Quantity]):

ImportString["[ \"Quantity\", 2.45, \"'Meters'\"]", "ExpressionJSON"]

Export an expression to a JSON string:

ExportString[{1,2,3}, "ExpressionJSON"]

ExportString[\[LeftAssociation]"x"->1,"y"->2, "z"->3\[RightAssociation], "ExpressionJSON", "Compact"->True]

Export a list while converting (RefLink[None, paclet:ref/None]) to JSON null:

ExportString[{True,None},"ExpressionJSON", "NullSymbols"->{None}]

Export a list of numbers of arbitrary precision:

ExportString[
<|"PlanckConstant"->6.626070040*10^−34,"AvogadroConstant"->6.02214*10^23,"Pi"->N[Pi,20]|>,"ExpressionJSON"]

Export a list of numbers and issue an error if any of them is not a machine-precision number:

ExportString[<|"PlanckConstant"->6.626070040*10^−34, "AvogadroConstant"->6.02214*10^23,"Pi"->N[Pi,20]|>,"ExpressionJSON", "PrecisionHandling"->False]

Control the output format with "Compact" to limit indentation:

ExportString[\[LeftAssociation]"x"->{{1,2},{3,4}},"y"->{{Null}}\[RightAssociation], "ExpressionJSON","Compact"->2]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {Related Formats:  (RefLink[RawJSON, paclet:ref/format/RawJSON])  ▪  (RefLink[JSON, paclet:ref/format/JSON])  ▪  (RefLink[UBJSON, paclet:ref/format/UBJSON])  ▪  (RefLink[BSON, paclet:ref/format/BSON])  ▪  (RefLink[XML, paclet:ref/format/XML])  ▪  (RefLink[ExpressionML, paclet:ref/format/ExpressionML])}})}})