-1

I saved a json into the database as a string like this:

"[_district:_1_2_5village, _name:_1_1_2id_inter, _gender:_1_3_5sex]"

Now i want to convert it back to a Json Object so as to pick the key and value eg _district is the key and _1_2_5village is the value. Any help on how i can achieve this. Thanks

I tried to convert the string back into JSON by parsing but that dint work for me.

2
  • 4
    json should look like this: { "_district": "_1_2_5village", "_name": "_1_1_2id_inter", "_gender": "_1_3_5sex" } Commented Nov 4, 2022 at 8:33
  • 2
    If you're saving invalid text into the database, you probably want to start with fixing that, instead of writing a custom parser Commented Nov 4, 2022 at 11:55

1 Answer 1

1

It doesn't work because that's not a JSON format, a JSON is a way of mapping objects and uses key value syntax like so:

{"key": "value"}

and an array would look like this:

[{"key": "value"},{"key": "value"}]

You'll need to make a custom parser for your syntax

Here's the json specification:

https://www.json.org/json-en.html

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response, Teddy. I fixed the format to save a JSON.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.