Git Product home page Git Product logo

.net-json-transformer's Introduction

.NET-JSON-Transformer

A Visual Basic .NET implementation that converts a JSON literal into a .NET XDocument

To use the file simply add it to your project and call the JSON.Parse method.

Syntax

Public Function Parse(ByVal source As String) As XDocument

Parameters

  • source

    • Type: System.String
    • The JSON literal to be converted.
  • Return Value

    • Type: System.Xml.Linq.XDocument
    • An XML representation of the JSON literal. If the JSON is not parsable, then the method returns Nothing.

Remarks

  • The parser ignores whitespace. So if the JSON literal is:
    {
      "string_key": [
        1,
        2,
        {
          "nested": true
        }
      ]
    }

Then it gets parsed as:

{"string_key":[1,2,{"nested":true}]}
  • The returned XML is a 1-to-1 translation from the JSON. Using the same example as above, the resulting XML would be:

    <object>
      <array name="string_key">
        <number>1</number>
        <number>2</number>
        <object>
          <boolean name="nested">true</boolean>
        </object>
      </array>
    </object>
    
  • The parser does not parse to the exact specifications of the EBNF found on http://www.json.org/ the following list the deviations in this parser:

    • Number: Checks if the number starts with either a positive sign or negative sign
    • Boolean: Checks for "true" or "false" based on case-insensitivity
    • Null: Checks for "null" based on case-insensitivity
    • String: Does not check for "\u" followed by 4 hexadecimal characters as an escape character

Examples and Demo:

The following example demonstrates the Parse method.

Option Strict On
Public Module Module1
    Public Sub Main()
  	  Dim jsonLiteral As String = "{""key"": [1, 2, 3], ""nested"": {""object"": true}}"
  	  Console.WriteLine(JSON.Parse(jsonLiteral))
    End Sub
End Module

Fiddle: https://dotnetfiddle.net/G707RC

.net-json-transformer's People

Contributors

dday9 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.